package saiboten.actions;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import saiboten.ChannelAction;

public class ReplaceAction implements ChannelAction {

	Map<String,String> previousActionPerChannel = new HashMap<String,String>();
	
	@Override
	public List<String> action(List<String> result, String channel,
			String sender, String message) {
		try {
		if(message.startsWith("s/")) {
			String[] splitMessage = message.split("/");
			String regExp = splitMessage[1];
			String replacer = splitMessage[2];
	
			result.add(previousActionPerChannel.get(channel+ "-" +sender).replaceAll(regExp, replacer));
		}
		
		previousActionPerChannel.put(channel+ "-" +sender, message);
		}
		catch(Exception u) {
			u.printStackTrace();
		}
		return result;
	}

}
